package com.niuxiaofa.newlaw.adapter;

import android.graphics.Color;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.niuxiaofa.newlaw.Bean.RankingBean;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.GlideUtils;
import com.niuxiaofa.newlaw.Tools.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class HarvesRankingAdapter extends RecyclerView.Adapter<HarvesRankingAdapter.ViewHolder> {
    public List<RankingBean.DataDTO> listEntities;
    Onclick onclick;

    int postion = 0;

    public HarvesRankingAdapter(List<RankingBean.DataDTO> newsList, Onclick onclick) {
        this.onclick = onclick;
        this.listEntities = newsList;
    }


    @Override
    public ViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_ranking, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder( ViewHolder viewHolder, int i) {

        RankingBean.DataDTO listEntity = listEntities.get(i);


        viewHolder.no.setVisibility(View.INVISIBLE);
        viewHolder.no_img.setVisibility(View.INVISIBLE);

        if (i == 0) {
            viewHolder.no_img.setVisibility(View.VISIBLE);
            viewHolder.no_img.setImageBitmap(UIUtils.getBitmap(R.mipmap.one));

        } else if (i == 1) {
            viewHolder.no_img.setVisibility(View.VISIBLE);
            viewHolder.no_img.setImageBitmap(UIUtils.getBitmap(R.mipmap.two));
        } else if (i == 2) {
            viewHolder.no_img.setVisibility(View.VISIBLE);
            viewHolder.no_img.setImageBitmap(UIUtils.getBitmap(R.mipmap.three));
        } else {
            viewHolder.no.setVisibility(View.VISIBLE);
        }
        viewHolder.no.setTextColor(Color.parseColor("#FF333333"));
        viewHolder.name.setTextColor(Color.parseColor("#FF333333"));
        viewHolder.value.setTextColor(Color.parseColor("#FFF83939"));
        viewHolder.no.setText(i +1+ "");
        viewHolder.name.setText(listEntity.getUserName());

        viewHolder.value.setText(listEntity.getEnergy()+"元");

        GlideUtils.loadUserImg(UIUtils.getContext(),listEntity.getHeader(),viewHolder.user_img);

    }

    @Override
    public int getItemCount() {
        return listEntities.size();
    }

    public interface Onclick {

        void onclick(int c);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.name)
        TextView name;

        @BindView(R.id.no_img)
        ImageView no_img;

        @BindView(R.id.no)
        TextView no;

        @BindView(R.id.user_img)
        ImageView user_img;

        @BindView(R.id.linear)
        LinearLayout linear;

        @BindView(R.id.value)
        TextView value;


        public ViewHolder( View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
